//获取url地址中的参数
function getSearchArg(argName) {
  // 去掉锚点连接
  let theHref = window.location.href; //http://localhost:3000/index.html?type=1#1234
  let searchStr;
  if (theHref.indexOf("#") > -1) {
      searchStr = theHref.substr(0, theHref.indexOf("#"));
  } else {
      searchStr = theHref.substr(0);
  }
   //searchStr  http://localhost:3000/index.html?type=1&sex=男
  let [, arr = ""] = searchStr.split("?");
  let argArr = arr.split("&");
  for (let i = 0; i < argArr.length; i++) {
      let smallArgArr = argArr[i].split("=");
      if (smallArgArr[0] === argName) {
          return decodeURIComponent(smallArgArr[1]);
      }
  }
  return "";
}
const host ="http://1272.0.0.1:3000";
//ajax的promise封装函数
function sendAjax({url="",type="get",data=null,dataType="json"}) {
    url=host+url;
    return new Promise( (resolve,reject)=>{
      $.ajax({
        url,
        type,
        data,
        dataType,
        success( response ){
          resolve( response ); //ajax请求成功，修改promise为成功状态并存储json数据
        },
        error( err ){
          reject( err ); //ajax请求失败，修改promise为失败状态并存储错误消息
        }
      })
    })
  } 

